home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / wgdb-42.lha / wgdb-4.2 / gdb / blockframe.c < prev    next >
C/C++ Source or Header  |  1992-09-11  |  21KB  |  744 lines

  1. /* Get info from stack frames;
  2.    convert between frames, blocks, functions and pc values.
  3.    Copyright (C) 1986, 1987, 1988, 1989 Free Software Foundation, Inc.
  4.  
  5. This file is part of GDB.
  6.  
  7. This program is free software; you can redistribute it and/or modify
  8. it under the terms of the GNU General Public License as published by
  9. the Free Software Foundation; either version 2 of the License, or
  10. (at your option) any later version.
  11.  
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. GNU General Public License for more details.
  16.  
  17. You should have received a copy of the GNU General Public License
  18. along with this program; if not, write to the Free Software
  19. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  20.  
  21. #include <stdio.h>
  22. #include "defs.h"
  23. #include "param.h"
  24. #include "symtab.h"
  25. #include "frame.h"
  26. #include "gdbcore.h"
  27. #include "value.h"        /* for read_register */
  28. #include "target.h"        /* for target_has_stack */
  29.  
  30. /* Required by INIT_EXTRA_FRAME_INFO on 88k.  */
  31. #include <setjmp.h>
  32. #include <obstack.h>
  33.  
  34. CORE_ADDR read_pc ();        /* In infcmd.c */
  35.  
  36. /* Start and end of object file containing the entry point.
  37.    STARTUP_FILE_END is the first address of the next file.
  38.    This file is assumed to be a startup file
  39.    and frames with pc's inside it
  40.    are treated as nonexistent.
  41.  
  42.    Setting these variables is necessary so that backtraces do not fly off
  43.    the bottom of the stack.  */
  44. CORE_ADDR startup_file_start;
  45. CORE_ADDR startup_file_end;
  46.  
  47. /* Is ADDR outside the startup file?  Note that if your machine
  48.    has a way to detect the bottom of the stack, there is no need
  49.    to call this function from FRAME_CHAIN_VALID; the reason for
  50.    doing so is that some machines have no way of detecting bottom
  51.    of stack.  */
  52. int
  53. outside_startup_file (addr)
  54.      CORE_ADDR addr;
  55. {
  56.   return !(addr >= startup_file_start && addr < startup_file_end);
  57. }
  58.  
  59. /* Support an alternate method to avoid running off the bottom of
  60.    the stack (or top, depending upon your stack orientation).
  61.  
  62.    There are two frames that are "special", the frame for the function
  63.    containing the process entry point, since it has no predecessor frame,
  64.    and the frame for the function containing the user code entry point
  65.    (the main() function), since all the predecessor frames are for the
  66.    process startup code.  Since we have no guarantee that the linked
  67.    in startup modules have any debugging information that gdb can use,
  68.    we need to avoid following frame pointers back into frames that might
  69.    have been built in the startup code, as we might get hopelessly 
  70.    confused.  However, we almost always have debugging information
  71.    available for main().
  72.  
  73.    These variables are used to save the range of PC values which are valid
  74.    within the main() function and within the function containing the process
  75.    entry point.  If we always consider the frame for main() as the outermost
  76.    frame when debugging user code, and the frame for the process entry
  77.    point function as the outermost frame when debugging startup code, then
  78.    all we have to do is have FRAME_CHAIN_VALID return false whenever a
  79.    frame's current PC is within the range specified by these variables.
  80.    In essence, we set "blocks" in the frame chain beyond which we will
  81.    not proceed when following the frame chain.  
  82.  
  83.    A nice side effect is that we can still debug startup code without
  84.    running off the end of the frame chain, assuming that we have usable
  85.    debugging information in the startup modules, and if we choose to not
  86.    use the block at main, or can't find it for some reason, everything
  87.    still works as before.  And if we have no startup code debugging
  88.    information but we do have usable information for main(), backtraces
  89.    from user code don't go wandering off into the startup code.
  90.  
  91.    To use this method, define your FRAME_CHAIN_VALID macro like:
  92.  
  93.     #define FRAME_CHAIN_VALID(chain, thisframe)     \
  94.       (chain != 0                                   \
  95.        && !(inside_main_scope ((thisframe)->pc))    \
  96.        && !(inside_entry_scope ((thisframe)->pc)))
  97.  
  98.    and add initializations of the four scope controlling variables inside
  99.    the object file / debugging information processing modules.  */
  100.  
  101. CORE_ADDR entry_scope_lowpc;
  102. CORE_ADDR entry_scope_highpc;
  103. CORE_ADDR main_scope_lowpc;
  104. CORE_ADDR main_scope_highpc;
  105.  
  106. /* Test a specified PC value to see if it is in the range of addresses
  107.    that correspond to the main() function.  See comments above for why
  108.    we might want to do this.
  109.  
  110.    Typically called from FRAME_CHAIN_VALID. */
  111.  
  112. int
  113. inside_main_scope (pc)
  114. CORE_ADDR pc;
  115. {
  116.   return (main_scope_lowpc <= pc && pc < main_scope_highpc);
  117. }
  118.  
  119. /* Test a specified PC value to see if it is in the range of addresses
  120.    that correspond to the process entry point function.  See comments above
  121.    for why we might want to do this.
  122.  
  123.    Typically called from FRAME_CHAIN_VALID. */
  124.  
  125. int
  126. inside_entry_scope (pc)
  127. CORE_ADDR pc;
  128. {
  129.   return (entry_scope_lowpc <= pc && pc < entry_scope_highpc);
  130. }
  131.  
  132. /* Address of innermost stack frame (contents of FP register) */
  133.  
  134. static FRAME current_frame;
  135.  
  136. /*
  137.  * Cache for frame addresses already read by gdb.  Valid only while
  138.  * inferior is stopped.  Control variables for the frame cache should
  139.  * be local to this module.
  140.  */
  141. struct obstack frame_cache_obstack;
  142.  
  143. /* Return the innermost (currently executing) stack frame.  */
  144.  
  145. FRAME
  146. get_current_frame ()
  147. {
  148.   /* We assume its address is kept in a general register;
  149.      param.h says which register.  */
  150.  
  151.   return current_frame;
  152. }
  153.  
  154. void
  155. set_current_frame (frame)
  156.      FRAME frame;
  157. {
  158.   current_frame = frame;
  159. }
  160.  
  161. FRAME
  162. create_new_frame (addr, pc)
  163.      FRAME_ADDR addr;
  164.      CORE_ADDR pc;
  165. {
  166.   struct frame_info *fci;    /* Same type as FRAME */
  167.  
  168.   fci = (struct frame_info *)
  169.     obstack_alloc (&frame_cache_obstack,
  170.            sizeof (struct frame_info));
  171.  
  172.   /* Arbitrary frame */
  173.   fci->next = (struct frame_info *) 0;
  174.   fci->prev = (struct frame_info *) 0;
  175.   fci->frame = addr;
  176.   fci->next_frame = 0;        /* Since arbitrary */
  177.   fci->pc = pc;
  178.  
  179. #ifdef INIT_EXTRA_FRAME_INFO
  180.   INIT_EXTRA_FRAME_INFO (fci);
  181. #endif
  182.  
  183.   return fci;
  184. }
  185.  
  186. /* Return the frame that called FRAME.
  187.    If FRAME is the original frame (it has no caller), return 0.  */
  188.  
  189. FRAME
  190. get_prev_frame (frame)
  191.      FRAME frame;
  192. {
  193.   /* We're allowed to know that FRAME and "struct frame_info *" are
  194.      the same */
  195.   return get_prev_frame_info (frame);
  196. }
  197.  
  198. /* Return the frame that FRAME calls (0 if FRAME is the innermost
  199.    frame).  */
  200.  
  201. FRAME
  202. get_next_frame (frame)
  203.      FRAME frame;
  204. {
  205.   /* We're allowed to know that FRAME and "struct frame_info *" are
  206.      the same */
  207.   return frame->next;
  208. }
  209.  
  210. /*
  211.  * Flush the entire frame cache.
  212.  */
  213. void
  214. flush_cached_frames ()
  215. {
  216.   /* Since we can't really be sure what the first object allocated was */
  217.   obstack_free (&frame_cache_obstack, 0);
  218.   obstack_init (&frame_cache_obstack);
  219.  
  220.   current_frame = (struct frame_info *) 0; /* Invalidate cache */
  221. }
  222.  
  223. /* Flush the frame cache, and start a new one if necessary.  */
  224. void
  225. reinit_frame_cache ()
  226. {
  227.   FRAME fr = current_frame;
  228.   flush_cached_frames ();
  229.   if (fr)
  230.     set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  231.                       read_pc ()));
  232. }
  233.  
  234. /* Return a structure containing various interesting information
  235.    about a specified stack frame.  */
  236. /* How do I justify including this function?  Well, the FRAME
  237.    identifier format has gone through several changes recently, and
  238.    it's not completely inconceivable that it could happen again.  If
  239.    it does, have this routine around will help */
  240.  
  241. struct frame_info *
  242. get_frame_info (frame)
  243.      FRAME frame;
  244. {
  245.   return frame;
  246. }
  247.  
  248. /* If a machine allows frameless functions, it should define a macro
  249.    FRAMELESS_FUNCTION_INVOCATION(FI, FRAMELESS) in param.h.  FI is the struct
  250.    frame_info for the frame, and FRAMELESS should be set to nonzero
  251.    if it represents a frameless function invocation.  */
  252.  
  253. /* Return nonzero if the function for this frame has a prologue.  Many
  254.    machines can define FRAMELESS_FUNCTION_INVOCATION to just call this
  255.    function.  */
  256.  
  257. int
  258. frameless_look_for_prologue (frame)
  259.      FRAME frame;
  260. {
  261.   CORE_ADDR func_start, after_prologue;
  262.   func_start = (get_pc_function_start (frame->pc) +
  263.         FUNCTION_START_OFFSET);
  264.   if (func_start)
  265.     {
  266.       after_prologue = func_start;
  267. #ifdef SKIP_PROLOGUE_FRAMELESS_P
  268.       /* This is faster, since only care whether there *is* a prologue,
  269.      not how long it is.  */
  270.       SKIP_PROLOGUE_FRAMELESS_P (after_prologue);
  271. #else
  272.       SKIP_PROLOGUE (after_prologue);
  273. #endif
  274.       return after_prologue == func_start;
  275.     }
  276.   else
  277.     /* If we can't find the start of the function, we don't really
  278.        know whether the function is frameless, but we should be able
  279.        to get a reasonable (i.e. best we can do under the
  280.        circumstances) backtrace by saying that it isn't.  */
  281.     return 0;
  282. }
  283.  
  284. #if !defined (INIT_FRAME_PC)
  285. #define INIT_FRAME_PC(fromleaf, prev) \
  286.   prev->pc = (fromleaf ? SAVED_PC_AFTER_CALL (prev->next) : \
  287.           prev->next ? FRAME_SAVED_PC (prev->next) : read_pc ());
  288. #endif
  289.  
  290. /* Return a structure containing various interesting information
  291.    about the frame that called NEXT_FRAME.  Returns NULL
  292.    if there is no such frame.  */
  293.  
  294. struct frame_info *
  295. get_prev_frame_info (next_frame)
  296.      FRAME next_frame;
  297. {
  298.   FRAME_ADDR address;
  299.   struct frame_info *prev;
  300.   int fromleaf = 0;
  301.  
  302.   /* If the requested entry is in the cache, return it.
  303.      Otherwise, figure out what the address should be for the entry
  304.      we're about to add to the cache. */
  305.  
  306.   if (!next_frame)
  307.     {
  308.       if (!current_frame)
  309.     {
  310.       error ("You haven't set up a process's stack to examine.");
  311.     }
  312.  
  313.       return current_frame;
  314.     }
  315.  
  316.   /* If we have the prev one, return it */
  317.   if (next_frame->prev)
  318.     return next_frame->prev;
  319.  
  320.   /* On some machines it is possible to call a function without
  321.      setting up a stack frame for it.  On these machines, we
  322.      define this macro to take two args; a frameinfo pointer
  323.      identifying a frame and a variable to set or clear if it is
  324.      or isn't leafless.  */
  325. #ifdef FRAMELESS_FUNCTION_INVOCATION
  326.   /* Still don't want to worry about this except on the innermost
  327.      frame.  This macro will set FROMLEAF if NEXT_FRAME is a
  328.      frameless function invocation.  */
  329.   if (!(next_frame->next))
  330.     {
  331.       FRAMELESS_FUNCTION_INVOCATION (next_frame, fromleaf);
  332.       if (fromleaf)
  333.     address = next_frame->frame;
  334.     }
  335. #endif
  336.  
  337.   if (!fromleaf)
  338.     {
  339.       /* Two macros defined in tm.h specify the machine-dependent
  340.      actions to be performed here.
  341.      First, get the frame's chain-pointer.
  342.      If that is zero, the frame is the outermost frame or a leaf
  343.      called by the outermost frame.  This means that if start
  344.      calls main without a frame, we'll return 0 (which is fine
  345.      anyway).
  346.  
  347.      Nope; there's a problem.  This also returns when the current
  348.      routine is a leaf of main.  This is unacceptable.  We move
  349.      this to after the ffi test; I'd rather have backtraces from
  350.      start go curfluy than have an abort called from main not show
  351.      main.  */
  352.       address = FRAME_CHAIN (next_frame);
  353.       if (!FRAME_CHAIN_VALID (address, next_frame))
  354.     return 0;
  355.       address = FRAME_CHAIN_COMBINE (address, next_frame);
  356.     }
  357.   if (address == 0)
  358.     return 0;
  359.  
  360.   prev = (struct frame_info *)
  361.     obstack_alloc (&frame_cache_obstack,
  362.            sizeof (struct frame_info));
  363.  
  364.   if (next_frame)
  365.     next_frame->prev = prev;
  366.   prev->next = next_frame;
  367.   prev->prev = (struct frame_info *) 0;
  368.   prev->frame = address;
  369.   prev->next_frame = prev->next ? prev->next->frame : 0;
  370.  
  371. #ifdef INIT_EXTRA_FRAME_INFO
  372.   INIT_EXTRA_FRAME_INFO(prev);
  373. #endif
  374.  
  375.   /* This entry is in the frame queue now, which is good since
  376.      FRAME_SAVED_PC may use that queue to figure out it's value
  377.      (see m-sparc.h).  We want the pc saved in the inferior frame. */
  378.   INIT_FRAME_PC(fromleaf, prev);
  379.  
  380.   return prev;
  381. }
  382.  
  383. CORE_ADDR
  384. get_frame_pc (frame)
  385.      FRAME frame;
  386. {
  387.   struct frame_info *fi;
  388.   fi = get_frame_info (frame);
  389.   return fi->pc;
  390. }
  391.  
  392. #if defined (FRAME_FIND_SAVED_REGS)
  393. /* Find the addresses in which registers are saved in FRAME.  */
  394.  
  395. void
  396. get_frame_saved_regs (frame_info_addr, saved_regs_addr)
  397.      struct frame_info *frame_info_addr;
  398.      struct frame_saved_regs *saved_regs_addr;
  399. {
  400.   FRAME_FIND_SAVED_REGS (frame_info_addr, *saved_regs_addr);
  401. }
  402. #endif
  403.  
  404. /* Return the innermost lexical block in execution
  405.    in a specified stack frame.  The frame address is assumed valid.  */
  406.  
  407. struct block *
  408. get_frame_block (frame)
  409.      FRAME frame;
  410. {
  411.   struct frame_info *fi;
  412.   CORE_ADDR pc;
  413.  
  414.   fi = get_frame_info (frame);
  415.  
  416.   pc = fi->pc;
  417.   if (fi->next_frame != 0)
  418.     /* We are not in the innermost frame.  We need to subtract one to
  419.        get the correct block, in case the call instruction was the
  420.        last instruction of the block.  If there are any machines on
  421.        which the saved pc does not point to after the call insn, we
  422.        probably want to make fi->pc point after the call insn anyway.  */
  423.     --pc;
  424.   return block_for_pc (pc);
  425. }
  426.  
  427. struct block *
  428. get_current_block ()
  429. {
  430.   return block_for_pc (read_pc ());
  431. }
  432.  
  433. CORE_ADDR
  434. get_pc_function_start (pc)
  435.      CORE_ADDR pc;
  436. {
  437.   register struct block *bl = block_for_pc (pc);
  438.   register struct symbol *symbol;
  439.   if (bl == 0 || (symbol = block_function (bl)) == 0)
  440.     {
  441.       register int misc_index = find_pc_misc_function (pc);
  442.       if (misc_index >= 0)
  443.     return misc_function_vector[misc_index].address;
  444.       return 0;
  445.     }
  446.   bl = SYMBOL_BLOCK_VALUE (symbol);
  447.   return BLOCK_START (bl);
  448. }
  449.  
  450. /* Return the symbol for the function executing in frame FRAME.  */
  451.  
  452. struct symbol *
  453. get_frame_function (frame)
  454.      FRAME frame;
  455. {
  456.   register struct block *bl = get_frame_block (frame);
  457.   if (bl == 0)
  458.     return 0;
  459.   return block_function (bl);
  460. }
  461.  
  462. /* Return the blockvector immediately containing the innermost lexical block
  463.    containing the specified pc value, or 0 if there is none.
  464.    PINDEX is a pointer to the index value of the block.  If PINDEX
  465.    is NULL, we don't pass this information back to the caller.  */
  466.  
  467. struct blockvector *
  468. blockvector_for_pc (pc, pindex)
  469.      register CORE_ADDR pc;
  470.      int *pindex;
  471. {
  472.   register struct block *b;
  473.   register int bot, top, half;
  474.   register struct symtab *s;
  475.   struct blockvector *bl;
  476.  
  477.   /* First search all symtabs for one whose file contains our pc */
  478.   s = find_pc_symtab (pc);
  479.   if (s == 0)
  480.     return 0;
  481.  
  482.   bl = BLOCKVECTOR (s);
  483.   b = BLOCKVECTOR_BLOCK (bl, 0);
  484.  
  485.   /* Then search that symtab for the smallest block that wins.  */
  486.   /* Use binary search to find the last block that starts before PC.  */
  487.  
  488.   bot = 0;
  489.   top = BLOCKVECTOR_NBLOCKS (bl);
  490.  
  491.   while (top - bot > 1)
  492.     {
  493.       half = (top - bot + 1) >> 1;
  494.       b = BLOCKVECTOR_BLOCK (bl, bot + half);
  495.       if (BLOCK_START (b) <= pc)
  496.     bot += half;
  497.       else
  498.     top = bot + half;
  499.     }
  500.  
  501.   /* Now search backward for a block that ends after PC.  */
  502.  
  503.   while (bot >= 0)
  504.     {
  505.       b = BLOCKVECTOR_BLOCK (bl, bot);
  506.       if (BLOCK_END (b) > pc)
  507.     {
  508.       if (pindex)
  509.         *pindex = bot;
  510.       return bl;
  511.     }
  512.       bot--;
  513.     }
  514.  
  515.   return 0;
  516. }
  517.  
  518. /* Return the innermost lexical block containing the specified pc value,
  519.    or 0 if there is none.  */
  520.  
  521. struct block *
  522. block_for_pc (pc)
  523.      register CORE_ADDR pc;
  524. {
  525.   register struct blockvector *bl;
  526.   int index;
  527.  
  528.   bl = blockvector_for_pc (pc, &index);
  529.   if (bl)
  530.     return BLOCKVECTOR_BLOCK (bl, index);
  531.   return 0;
  532. }
  533.  
  534. /* Return the function containing pc value PC.
  535.    Returns 0 if function is not known.  */
  536.  
  537. struct symbol *
  538. find_pc_function (pc)
  539.      CORE_ADDR pc;
  540. {
  541.   register struct block *b = block_for_pc (pc);
  542.   if (b == 0)
  543.     return 0;
  544.   return block_function (b);
  545. }
  546.  
  547. /* These variables are used to cache the most recent result
  548.  * of find_pc_partial_function. */
  549.  
  550. static CORE_ADDR cache_pc_function_low = 0;
  551. static CORE_ADDR cache_pc_function_high = 0;
  552. static char *cache_pc_function_name = 0;
  553.  
  554. /* Clear cache, e.g. when symbol table is discarded. */
  555.  
  556. void
  557. clear_pc_function_cache()
  558. {
  559.   cache_pc_function_low = 0;
  560.   cache_pc_function_high = 0;
  561.   cache_pc_function_name = (char *)0;
  562. }
  563.  
  564. /* Finds the "function" (text symbol) that is smaller than PC
  565.    but greatest of all of the potential text symbols.  Sets
  566.    *NAME and/or *ADDRESS conditionally if that pointer is non-zero.
  567.    Returns 0 if it couldn't find anything, 1 if it did.  On a zero
  568.    return, *NAME and *ADDRESS are always set to zero.  On a 1 return,
  569.    *NAME and *ADDRESS contain real information.  */
  570.  
  571. int
  572. find_pc_partial_function (pc, name, address)
  573.      CORE_ADDR pc;
  574.      char **name;
  575.      CORE_ADDR *address;
  576. {
  577.   struct partial_symtab *pst;
  578.   struct symbol *f;
  579.   int miscfunc;
  580.   struct partial_symbol *psb;
  581.  
  582.   if (pc >= cache_pc_function_low && pc < cache_pc_function_high)
  583.     {
  584.     if (address)
  585.         *address = cache_pc_function_low;
  586.     if (name)
  587.         *name = cache_pc_function_name;
  588.     return 1;
  589.     }
  590.  
  591.   pst = find_pc_psymtab (pc);
  592.   if (pst)
  593.     {
  594.       if (pst->readin)
  595.     {
  596.       /* The information we want has already been read in.
  597.          We can go to the already readin symbols and we'll get
  598.          the best possible answer.  */
  599.       f = find_pc_function (pc);
  600.       if (!f)
  601.         {
  602.         return_error:
  603.           /* No available symbol.  */
  604.           if (name != 0)
  605.         *name = 0;
  606.           if (address != 0)
  607.         *address = 0;
  608.           return 0;
  609.         }
  610.  
  611.       cache_pc_function_low = BLOCK_START (SYMBOL_BLOCK_VALUE (f));
  612.       cache_pc_function_high = BLOCK_END (SYMBOL_BLOCK_VALUE (f));
  613.       cache_pc_function_name = SYMBOL_NAME (f);
  614.       if (name)
  615.         *name = cache_pc_function_name;
  616.       if (address)
  617.         *address = cache_pc_function_low;
  618.       return 1;
  619.     }
  620.  
  621.       /* Get the information from a combination of the pst
  622.      (static symbols), and the misc function vector (extern
  623.      symbols).  */
  624.       miscfunc = find_pc_misc_function (pc);
  625.       psb = find_pc_psymbol (pst, pc);
  626.  
  627.       if (!psb && miscfunc == -1)
  628.     {
  629.       goto return_error;
  630.     }
  631.       if (psb
  632.       && (miscfunc == -1
  633.           || (SYMBOL_VALUE_ADDRESS (psb)
  634.           >= misc_function_vector[miscfunc].address)))
  635.     {
  636.       /* This case isn't being cached currently. */
  637.       if (address)
  638.         *address = SYMBOL_VALUE_ADDRESS (psb);
  639.       if (name)
  640.         *name = SYMBOL_NAME (psb);
  641.       return 1;
  642.     }
  643.     }
  644.   else
  645.     /* Must be in the misc function stuff.  */
  646.     {
  647.       miscfunc = find_pc_misc_function (pc);
  648.       if (miscfunc == -1)
  649.     goto return_error;
  650.     }
  651.  
  652.   {
  653.     if (misc_function_vector[miscfunc].type == mf_text)
  654.       cache_pc_function_low = misc_function_vector[miscfunc].address;
  655.     else
  656.       /* It is a transfer table for Sun shared libraries.  */
  657.       cache_pc_function_low = pc - FUNCTION_START_OFFSET;
  658.   }
  659.   cache_pc_function_name = misc_function_vector[miscfunc].name;
  660.   if (miscfunc < misc_function_count /* && FIXME mf_text again? */ )
  661.     cache_pc_function_high = misc_function_vector[miscfunc+1].address;
  662.   else
  663.     cache_pc_function_high = cache_pc_function_low + 1;
  664.   if (address)
  665.     *address = cache_pc_function_low;
  666.   if (name)
  667.     *name = cache_pc_function_name;
  668.   return 1;
  669. }
  670.  
  671. /* Find the misc function whose address is the largest
  672.    while being less than PC.  Return its index in misc_function_vector.
  673.    Returns -1 if PC is not in suitable range.  */
  674.  
  675. int
  676. find_pc_misc_function (pc)
  677.      register CORE_ADDR pc;
  678. {
  679.   register int lo = 0;
  680.   register int hi = misc_function_count-1;
  681.   register int new;
  682.  
  683.   /* Note that the last thing in the vector is always _etext.  */
  684.   /* Actually, "end", now that non-functions
  685.      go on the misc_function_vector.  */
  686.  
  687.   /* Above statement is not *always* true - fix for case where there are */
  688.   /* no misc functions at all (ie no symbol table has been read). */
  689.   if (hi < 0) return -1;        /* no misc functions recorded */
  690.  
  691.   /* trivial reject range test */
  692.   if (pc < misc_function_vector[0].address ||
  693.       pc > misc_function_vector[hi].address)
  694.     return -1;
  695.  
  696.   /* Note that the following search will not return hi if
  697.      pc == misc_function_vector[hi].address.  If "end" points to the
  698.      first unused location, this is correct and the above test
  699.      simply needs to be changed to
  700.      "pc >= misc_function_vector[hi].address".  */
  701.   do {
  702.     new = (lo + hi) >> 1;
  703.     if (misc_function_vector[new].address == pc)
  704.       return new;        /* an exact match */
  705.     else if (misc_function_vector[new].address > pc)
  706.       hi = new;
  707.     else
  708.       lo = new;
  709.   } while (hi-lo != 1);
  710.  
  711.   /* if here, we had no exact match, so return the lower choice */
  712.   return lo;
  713. }
  714.  
  715. /* Return the innermost stack frame executing inside of the specified block,
  716.    or zero if there is no such frame.  */
  717.  
  718. FRAME
  719. block_innermost_frame (block)
  720.      struct block *block;
  721. {
  722.   struct frame_info *fi;
  723.   register FRAME frame;
  724.   register CORE_ADDR start = BLOCK_START (block);
  725.   register CORE_ADDR end = BLOCK_END (block);
  726.  
  727.   frame = 0;
  728.   while (1)
  729.     {
  730.       frame = get_prev_frame (frame);
  731.       if (frame == 0)
  732.     return 0;
  733.       fi = get_frame_info (frame);
  734.       if (fi->pc >= start && fi->pc < end)
  735.     return frame;
  736.     }
  737. }
  738.  
  739. void
  740. _initialize_blockframe ()
  741. {
  742.   obstack_init (&frame_cache_obstack);
  743. }
  744.